package com.codi.bus.core.service;

import com.codi.bus.core.resultModel.BaseResult;
import com.codi.bus.core.vo.BasicSellVo;
import com.codi.bus.core.vo.BuyVo;
import com.codi.bus.core.vo.SellVo;
import com.codi.bus.core.vo.TradeStatusVo;
import com.codi.bus.exception.BaseException;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

public interface TradeService {
    // 申购基金
    BaseResult buy(Long userId, String token, String bankAccount, String paymentType, Integer moneyType,
                   String fundName, String fundCode, BigDecimal fundBalance, String shareType, String tradePassword,
                   String applyNo) throws BaseException;

    /**
     * 基金申购(包括赎回转购)
     *
     * @param vo
     * @return
     * @author spy
     * @date 2017-11-30 14:08:55
     */
    BaseResult buy(BuyVo vo);


    // 赎回基金
    BaseResult sell(Long userId, String token, String bankAccount, String paymentType, String fundName, String fundCode,
                    BigDecimal shares, String shareType, String tradePassword, String applyNo) throws BaseException;

    @Transactional
    BaseResult sellForWallet(SellVo sellVo);

    BaseResult sellReal(Long userId, String channelId, String bankAccount, String capitalMode, String fundName,
                        String fundCode, BigDecimal shares, String shareType, String tradePassword, String applyNo) throws BaseException;

    /**
     * 赎回基金
     *
     * @param vo
     * @return
     * @author spy 2017-11-14 15:56:48
     */
    BaseResult sell(BasicSellVo vo);

    // 撤单
    BaseResult undo(Long userId, String token, String originalApplyNo, String tradePassword) throws BaseException;

    BaseResult undoReal(Long userId, String channelId, String originalApplyNo, String tradePassword, boolean isOrg) throws BaseException;

    /**
     * 定投申购
     *
     * @param applyNo
     * @param tradePassword
     * @param protocolFixDay
     * @param shareType
     * @param bankAccount
     * @param fundName
     * @param protocolPeriodUnit
     * @param userId
     * @param balance
     * @param fundCode
     * @param capitalMode
     * @param token
     * @return
     * @throws BaseException
     */
    BaseResult fix(String applyNo, String tradePassword, Long protocolFixDay, String shareType, String bankAccount,
                   String fundName, String protocolPeriodUnit, long userId, BigDecimal balance, String fundCode,
                   String capitalMode, String token, String fixModel, String oldExternalScheduledProtocolId, String expiryDate)
        throws BaseException;

    BaseResult fixReal(String applyNo, String tradePassword, Long protocolFixDay, String shareType,
                       String bankAccount, String fundName, String protocolPeriodUnit, long userId, BigDecimal balance,
                       String fundCode, String capitalMode, String channelId, String fixModel, String oldExternalScheduledProtocolId,
                       String expiryDate) throws BaseException;

    /**
     * 快速赎回
     *
     * @param userId        用户Id
     * @param token         Token
     * @param capitalMode   资金方式
     * @param tradePassword 交易密码
     * @param fundCode      基金代码
     * @param shareType     份额类型
     * @param shares        份额
     * @param bankAccount   银行账户
     * @param fundName      基金名称
     * @param applyNo       申请编号
     * @param tradeAcco     交易账号
     * @return 赎回结果
     */
    BaseResult fastRedeem(Long userId, String token, String capitalMode, String tradePassword, String fundCode,
                          String shareType, BigDecimal shares, String bankAccount, String fundName, String applyNo, String tradeAcco);

    BaseResult fastRedeemReal(Long userId, String channelId, String capitalMode, String tradePassword, String fundCode,
                              String shareType, BigDecimal shares, String bankAccount, String fundName, String applyNo);

    /**
     * 交易状态更细为成功
     *
     * @param tradeStatusVo
     * @return
     */
    void updateTradeStatusSuc(TradeStatusVo tradeStatusVo);


    /**
     * 交易状态更新为失败
     *
     * @param tradeStatusVo
     * @return
     */
    void updateTradeStatusFail(TradeStatusVo tradeStatusVo);


    void storeData(Map<String, Object> map, String capitalMode, String bankCode, String bankAccount,
                   BigDecimal shares, BigDecimal orderBalance, String orderSn, Long userId, String channelId, String tradeType,
                   Integer orderStatus, Date applyDate, String externalApplyNo, String fundCode, String fundName,
                   String shareType, Integer fundStatus, Long protocolFixDay, String protocolPeriodUnit,
                   String externalScheduledProtocolId);
}
